It is common for a computer processor and associated operating system to have two different levels of resources and protection. One level, referred to as a non-privileged mode or user mode, is used by various operating system components, application programs, and other so-called “user” processes or programs. At this level, an execution thread is prevented by the operating system and by the computer processor from performing certain security-critical operations. The thread is also prevented from directly accessing many system resources. The purpose of the non-privileged execution mode is to isolate a user process as much as possible so that it cannot interfere with other user processes or with operating system functions.
User-mode drivers run in the nonprivileged processor mode in which other application code, including protected subsystem code, executes. User-mode drivers cannot gain access to system data except by making a syscall which, in turn, calls system services. While a user process may itself crash, it should not be able to crash other programs or the operating system.
The other level of execution is referred to as privileged mode, system mode, or kernel mode. Critical operating system components are implemented in kernel mode. Kernel-mode components are responsible for things like virtual memory management, responding to interrupts and exceptions, scheduling execution threads, synchronizing the activities of multiple processors, and other critical or sensitive functions. Such components, which execute from system mode, are generally referred to collectively as “the kernel.”
Kernel-mode drivers run as part of the operating system's executive, the underlying operating system component that supports one or more protected subsystems. User-mode and kernel-mode drivers have different structures, different entry points, and different system interfaces. Whether a device requires a user-mode or kernel-mode driver depends on the type of device and the support already provided for it in the operating system. Some device drivers can run wholly or partially in user mode. User-mode drivers have unlimited stack space, access to one or more APIs, and easier debugging.
Most device drivers run in kernel mode. Kernel-mode drivers can perform certain protected operations and can access system structures that user-mode drivers cannot access. The increased access comes at the price, however, of more difficult debugging and a greater chance of system corruption. When code runs in the privileged kernel-mode environment, the operating system, by design, performs fewer checks on data integrity and the validity of requests.